﻿<navigation:Page x:Class="InsuranceAdjuster.Views.SyncStatusView" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:swd="clr-namespace:System.Windows.Data;assembly=System.Windows"
           xmlns:compMod="clr-namespace:System.ComponentModel;assembly=System.Windows"
           xmlns:helpers="clr-namespace:InsuranceAdjuster.Helpers"
           d:DesignWidth="640" d:DesignHeight="300"
           MinHeight="300"
           DataContext="{Binding SyncStatus, Source={StaticResource Locator}}" 
           Title="SyncStatusView Page"
           HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <navigation:Page.Resources>

        <Style x:Name="MessageName" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource MainFont}"/>
            <Setter Property="Foreground" Value="{StaticResource MainTextColor}"/>
            <Setter Property="Margin" Value="4" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="FontWeight" Value="Bold" />
        </Style>
        <Style x:Name="MessageLabelText" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource MainFont}"/>
            <Setter Property="Foreground" Value="{StaticResource MainTextColor}"/>
            <Setter Property="Margin" Value="4" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="FontWeight" Value="Bold" />
        </Style>
        <Style x:Name="MessageValueText" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource MainFont}"/>
            <Setter Property="Foreground" Value="{StaticResource MainTextColor}"/>
            <Setter Property="Margin" Value="4" />
            <Setter Property="FontSize" Value="10" />
        </Style>
        <helpers:VisibilityConverter x:Key="VisibilityConverter" />
        <helpers:NotVisibilityConverter x:Key="NotVisibilityConverter" />

        <swd:CollectionViewSource x:Key="SortedFilteredMessages" Source="{Binding Path=FilteredMessages}" >
            <swd:CollectionViewSource.SortDescriptions>
                <compMod:SortDescription PropertyName="GroupName" Direction="Ascending"/>
                <compMod:SortDescription PropertyName="MessageName" Direction="Ascending"/>
                <compMod:SortDescription PropertyName="ExecutionStartedAt" Direction="Ascending"/>
            </swd:CollectionViewSource.SortDescriptions>
        </swd:CollectionViewSource>

    </navigation:Page.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <CheckBox Grid.Row="0"
                  Grid.Column="0"
                  Content="Show Completed Messages"
                  IsChecked="{Binding ShowCompletedMessages, Mode=TwoWay}" />

        <StackPanel Grid.Row="0"
                    Grid.Column="1"
                    Orientation="Horizontal"/>

        <ScrollViewer Grid.Row="1" Grid.ColumnSpan="99" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="130" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="130" />
                    <ColumnDefinition Width="110" />
                </Grid.ColumnDefinitions>

                    <TextBlock Text="Group" Grid.Column="0" Style="{StaticResource MessageLabelText}" />
                    <TextBlock Text="Message" Grid.Column="1"  Style="{StaticResource MessageLabelText}" />
                <TextBlock Text="Time" Grid.Column="2" Style="{StaticResource MessageLabelText}" HorizontalAlignment="Right" />
                <TextBlock Text="Status" Grid.Column="3"  Style="{StaticResource MessageLabelText}" HorizontalAlignment="Right" />

                <ItemsControl Grid.Row="1" Grid.ColumnSpan="99" ItemsSource="{Binding Source={StaticResource SortedFilteredMessages}}"
                          HorizontalAlignment="Stretch">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="130" />
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="130" />
                                        <ColumnDefinition Width="110" />
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Grid.Column="0" Text="{Binding GroupName}" Style="{StaticResource MessageValueText}" />
                                    <TextBlock Grid.Column="1" Text="{Binding MessageName}" Style="{StaticResource MessageName}" />
                                    <TextBlock Grid.Column="2" Text="{Binding ExecutionStartedAt}" Style="{StaticResource MessageValueText}" HorizontalAlignment="Right" />
                                    <TextBlock Grid.Column="3" Text="{Binding Status}" Style="{StaticResource MessageValueText}" HorizontalAlignment="Right" />

                                </Grid>
                            </StackPanel>  
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
        </ScrollViewer>
    </Grid>
</navigation:Page>
